package me.minecraft.woodenman.command;

import me.minecraft.woodenman.WoodenMan;
import me.minecraft.woodenman.config.Language;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

/**
 * @author langle__
 * @version 1.0
 */
public class QuitCommand implements CommandExecutor {

    @Override
    public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
        if (!(sender instanceof Player)) {
            sender.sendMessage(Language.ONLY_PLAYER_CAN_USE);
            return false;
        }
        Player player = (Player) sender;
        if (WoodenMan.gameTask == null) {
            sender.sendMessage(Language.GAME_NOT_STARTED);
            return false;
        }
        if (!WoodenMan.gameTask.isPlayerInGame(player)) {
            sender.sendMessage(Language.PLAYER_NOT_IN_GAME);
            return false;
        }
        if (WoodenMan.gameTask.removePlayer(player)) {
            player.sendMessage(Language.QUIT_GAME_SUCCESS);
            return true;
        } else {
            player.sendMessage(Language.QUIT_GAME_FAILED);
        }
        return false;
    }

}
